﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Collections;
using System.Data;

using Web.SystemConfig.ArchiveCode;
using ePlanet.ArchiveMange.Models;
using ePlanet.ArchiveMange.Services;
using DreamBuilder.Core.Container;
using Microsoft.Practices.Unity;
using ePlanet.ArchiveMange.Enum;
using System.IO;

/*
 * 查询使用说明
 * 1. 需要在aspx页面添加 EnableEventValidation=false 
 * 2. 在按钮工具栏中添加按钮
 * 3. 添加查询框div
 * 4. 定义 Page_Init 方法，调用 CommonSearchHelper.BuildSearchTable 初始化查询组件
 * 5. 实现 BtnFilter_Click事件 调用 CommonSearchHelper.GetWhere 取查询条件SQL
 * 6. 添加js脚本控制显示和隐藏查询框
 */

namespace Web.Views.ArchiveFlowView
{
    public partial class ArchiveDoneList : ArchiveFlowPageBase
    {
        [Dependency]
        public IArchiveMenuService ArchiveMenuService
        {
            get;
            set;
        }

        [Dependency]
        public IPageFileService PageFileService
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //基类控件赋值
            PassFlowName = hiddenSHTG.Value;
            BackFlowName = hiddenBack.Value;
            gvTransfered = gvDocumentDone;
            gvUnTransfered = gvDocumentUndo;
            pagerTransfered = pagerDone;
            pagerUntransfered = pagerUndo;

            ///时间：2012年12月15日 13:16:40
            ///添加未生成档号列表
            gvUntransferedWithNoArchiveNum = gvDocumentUndoWithNoArchiveNum;
            pagerUntransferedWithNoArchiveNum = pagerUndoWithNoArchiveNum;
            CurrentStatusName = hiddenStatusName.Value;

            this.sch.SearchEvent += new EventHandler(sch_SearchEvent);

            searchCtrl = sch;

            pagerTransfered.PageSizeChanging += new EventHandler(pagerTransfered_PageSizeChanging);
            pagerUntransfered.PageSizeChanging += new EventHandler(pagerUntransfered_PageSizeChanging);

            switch (BaseArchiveType)
            {
                case ArchiveBaseType.Document:
                case ArchiveBaseType.CDKind:
                case ArchiveBaseType.OliSearch:
                case ArchiveBaseType.AudioVedio:
                case ArchiveBaseType.RealKind:
                    this.gvDocumentUndoWithNoArchiveNum.Columns[7].HeaderText = "责任者";
                    break;
                case ArchiveBaseType.Technology:
                case ArchiveBaseType.BulidProject:
                case ArchiveBaseType.Equipment:
                case ArchiveBaseType.Account:
                    this.gvDocumentUndoWithNoArchiveNum.Columns[7].HeaderText = "立卷单位";
                    break;
            }

            if (!IsPostBack)
            {
                //调用基类方法初始化页面数据
                InitialData();

                //初始化档号流水
                this.txtArchiveCodeNumber.Text = 
                    ArchiveCodeGenerateHelper.GetCurrArchiveCodeNum(CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum).ToString();
            }
            else
            {
                //
            }
        }

        /// <summary>
        /// 代办数据绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvNewUnTransfered_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRow row = ((DataRowView)e.Row.DataItem).Row;
                string elecFileCount = ArchiveBusiHelper.Instance.GetTechnologyFileCount((int)BaseArchiveType, row["dataid"].ToString());
                if (!string.IsNullOrEmpty(elecFileCount))
                {
                    e.Row.Cells[1].Text = string.Format("<img src='{0}' alt='{1}个电子文件' />",
                        "../../Images/qbz.jpg", elecFileCount);
                }
                else
                {
                    e.Row.Cells[1].Text = string.Empty;
                }
                e.Row.Cells[4].Text = IUserService.GetUserNameById(row["CREATEUSERID"].ToString());
                e.Row.Cells[5].Text = string.Format("<a target='_blank' href='ArchiveFlowEdit.aspx?archiveId={0}&archivetype={1}&currentstatusname={2}' >{3}</a>",
                    row["DATAID"], (int)CurrentArchiveKind, CurrentStatusName, row["TITLE"]);

                string[] publishTimeStrArr = row["publishtime"].ToString().Split(new char[] { '~' }, StringSplitOptions.RemoveEmptyEntries);
                if (publishTimeStrArr.Length == 1)
                {
                    e.Row.Cells[11].Text = publishTimeStrArr[0];
                }
                else if (publishTimeStrArr.Length == 2)
                {
                    e.Row.Cells[11].Text = string.Format("{0}<br />~<br />{1}",
                        publishTimeStrArr[0], publishTimeStrArr[1]);
                }

                e.Row.Cells[12].Text = elecFileCount.ToString();
            }
        }


        /// <summary>
        /// 查询事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void sch_SearchEvent(object sender, EventArgs e)
        {
            InitialData(this.sch.WhereString);
        }

        /// <summary>
        /// 生成档号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnGenerateArchiveCode_Click(object sender, EventArgs e)
        {
            ArrayList keys = this.gvDocumentUndoWithNoArchiveNum.SelectItems;
            if (keys.Count == 0)
            {
                Alert("请先选择待生成档号的条目！");
                return;
            }
            int quanzonghaoSeriesNum = 0;
            if (!int.TryParse(this.txtArchiveCodeNumber.Text.Trim(), out quanzonghaoSeriesNum) || quanzonghaoSeriesNum <= 0)
            {
                Alert("当前分类档号流水号无效！");
                return;
            }
            int currSeriesNum = ArchiveCodeGenerateHelper.GetCurrArchiveCodeNum(CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum);
            if (quanzonghaoSeriesNum < currSeriesNum)
            {
                //this.txtArchiveCodeNumber.Text = currSeriesNum.ToString();
                //Alert("当前分类档号流水号已经存在！");
                //return;

                //修改：2013年7月17日 22:05:01
                //支持按照手动输入的已经过期的流水号来为至多一条档案生成档号/
                if (ExistArchiveCode(CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, string.Empty, quanzonghaoSeriesNum))
                {
                    this.txtArchiveCodeNumber.Text = currSeriesNum.ToString();
                    Alert("当前分类档号流水号已经存在！");
                    return;
                }
                else
                {
                    if (keys.Count > 1)
                    {
                        Alert("输入的流水号过期，至多只能选择一条档案！");
                        return;
                    }
                }
            }
            int baseTypeId = ArchiveMenuService.GetArchiveBaseIDById((int)CurrentArchiveKind);
            int i = 0;
            switch (baseTypeId)
            {
                //文书类
                case ((int)ArchiveBaseType.Document):
                    DocumentArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //会计类
                case ((int)ArchiveBaseType.Account):
                    AccountArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //基建类
                case ((int)ArchiveBaseType.BulidProject):
                    BuildProjectArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //设备类
                case ((int)ArchiveBaseType.Equipment):
                    EquipArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //油气勘探类
                case ((int)ArchiveBaseType.OliSearch):
                    OliSearchArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //音像类
                case ((int)ArchiveBaseType.AudioVedio):
                    AudioArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //实物类
                case ((int)ArchiveBaseType.RealKind):
                    RealKindArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //科研类
                case ((int)ArchiveBaseType.Technology):
                    TechArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
                //光盘类
                case ((int)ArchiveBaseType.CDKind):
                    CDArchiveGenerate(keys, quanzonghaoSeriesNum, ref i);
                    break;
            }

            //初始化档号流水
            this.txtArchiveCodeNumber.Text =
                ArchiveCodeGenerateHelper.GetCurrArchiveCodeNum(
                CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum).ToString();
            BindAgent();
            Alert("成功为" + i.ToString() + "条档案生成档号！");
            return;
        }

        /// <summary>
        /// 判断档号是否存在
        /// </summary>
        /// <param name="archiveType">档案类型</param>
        /// <param name="quanzonghao">全宗号</param>
        /// <param name="seriesNumber">流水号</param>
        /// <returns></returns>
        public static bool ExistArchiveCode(Web.SystemConfig.WorkFlow.ArchiveTableEnum archiveType, string quanzonghao, string jh, int seriesNumber)
        {
            //按照传入的流水号生成档号
            string archiveCode = ArchiveCodeGenerateHelper.Generate(archiveType, quanzonghao, jh, ref seriesNumber);
            bool isExist = false;
            switch (archiveType)
            {
                //************************ W-0000001
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.Document:
                    IDocumentArchiveService DocumentArchiveService = UContainer.Resolve<IDocumentArchiveService>();
                    ArchiveMangeModal.DOCUMENT_ARCHIVEDataTable dt = DocumentArchiveService.GetAllDocumenArchivetDataById(archiveCode);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.CDKind:
                    ICDArchiveService CDArchiveService = UContainer.Resolve<ICDArchiveService>();
                    ArchiveMangeModal.CD_ARCHIVEDataTable cdTable = CDArchiveService.GetAllDocumenArchivetDataById(archiveCode);
                    if (cdTable != null && cdTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.Technology:
                    ITechArchiveService techArchvieService = UContainer.Resolve<ITechArchiveService>();
                    ArchiveMangeModal.TECHNOLOGY_ARCHIVEDataTable techTable = techArchvieService.GetAllDocumenArchivetDataById(archiveCode);
                    if (techTable != null && techTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.BulidProject:
                    IBuildProjectArchiveService buildArchvieService = UContainer.Resolve<IBuildProjectArchiveService>();
                    ArchiveMangeModal.BULIDPROJECT_ARCHIVEDataTable buildTable = buildArchvieService.GetAllDocumenArchivetDataById(archiveCode);
                    if (buildTable != null && buildTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.Equipment:
                    IEquipmentService equipmentArchvieService = UContainer.Resolve<IEquipmentService>();
                    ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable equipmentTable = equipmentArchvieService.GetAllDocumenArchivetDataById(archiveCode);
                    if (equipmentTable != null && equipmentTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.RealKindR01:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.RealKindR02:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.RealKindR03:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.RealKindR04:
                    IRealKindArchiveService realkindArchvieService = UContainer.Resolve<IRealKindArchiveService>();
                    ArchiveMangeModal.REALKIND_ARCHIVEDataTable realkindTable = realkindArchvieService.GetAllDocumenArchivetDataById(archiveCode);
                    if (realkindTable != null && realkindTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;

                //*****************会计类******************* I01-2012-0001      I02-0000001
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.AccountI01:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.AccountI02:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.AccountI03:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.AccountI04:
                    IAccountArchiveService accountArchvieService = UContainer.Resolve<IAccountArchiveService>();
                    ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVEDataTable accountTable = accountArchvieService.GetAllDocumenArchivetDataById(archiveCode);
                    if (accountTable != null && accountTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;

                //*****************勘探开发单井类************* K-井号-001
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.OliSearchK01:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.OliSearchK02:
                    IOilSearchArchiveService oilArchvieService = UContainer.Resolve<IOilSearchArchiveService>();
                    ArchiveMangeModal.OLISEARCH_ARCHIVEDataTable oilTable = oilArchvieService.GetAllDocumenArchivetDataById(archiveCode);
                    if (oilTable != null && oilTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;

                //*****************声像类******************** S03-0000001
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.AudioVedioS01:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.AudioVedioS02:
                case Web.SystemConfig.WorkFlow.ArchiveTableEnum.AudioVedioS03:
                    IAudioArchiveService audioArchvieService = UContainer.Resolve<IAudioArchiveService>();
                    ArchiveMangeModal.AUDIOVEDIO_ARCHIVEDataTable audioTable = audioArchvieService.GetAllDocumenArchivetDataById(archiveCode);
                    if (audioTable != null && audioTable.Rows.Count > 0)
                    {
                        isExist = true;
                    }
                    break;
            }
            return isExist;
        }

        protected void btnDeleteArchiveCode_Click(object sender, EventArgs e)
        {
            ArrayList keys = this.gvDocumentUndo.SelectItems;
            if (keys.Count == 0)
            {
                Alert("请先选择待删除档号的条目！");
                return;
            }
            int baseTypeId = ArchiveMenuService.GetArchiveBaseIDById((int)CurrentArchiveKind);
            int i = 0;
            switch (baseTypeId)
            {
                //文书类
                case ((int)ArchiveBaseType.Document):
                    DocumentArchiveCodeDelete(keys, ref i);
                    break;
                //会计类
                case ((int)ArchiveBaseType.Account):
                    AccountArchiveCodeDelete(keys, ref i);
                    break;
                //基建类
                case ((int)ArchiveBaseType.BulidProject):
                    BuildProjectArchiveCodeDelete(keys, ref i);
                    break;
                //设备类
                case ((int)ArchiveBaseType.Equipment):
                    EquipArchiveCodeDelete(keys, ref i);
                    break;
                //油气勘探类
                case ((int)ArchiveBaseType.OliSearch):
                    OliSearchArchiveCodeDelete(keys, ref i);
                    break;
                //音像类
                case ((int)ArchiveBaseType.AudioVedio):
                    AudioArchiveCodeDelete(keys, ref i);
                    break;
                //实物类
                case ((int)ArchiveBaseType.RealKind):
                    RealKindArchiveCodeDelete(keys, ref i);
                    break;
                //科研类
                case ((int)ArchiveBaseType.Technology):
                    TechArchiveCodeDelete(keys, ref i);
                    break;
                //光盘类
                case ((int)ArchiveBaseType.CDKind):
                    CDArchiveCodeDelete(keys, ref i);
                    break;
            }

            BindAgent();
            Alert(i.ToString() + "条档案已删除档号！");
            return;
        }

        protected void btnPrintArchiveMenu_Click(object sender, EventArgs e)
        {
            ArrayList keys = new ArrayList();
            keys = this.gvDocumentUndo.SelectItems;
            keys.AddRange(this.gvDocumentUndoWithNoArchiveNum.SelectItems);
            keys.AddRange(this.gvDocumentDone.SelectItems);
            if (keys.Count == 0)
            {
                Alert("未选中任何数据！");
                return;
            }
            Session["selectedkeys"] = keys;
            this.Response.Redirect(string.Format("PrintEntCatagory.aspx?from=dazl&archiveType={0}", (int)CurrentArchiveKind));
        }

        /// <summary>
        /// 备注：打印档案交接文具
        /// 时间：2013年3月12日 23:21:21
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPrintHandoverCatagory_Click(object sender, EventArgs e)
        {
            ArrayList keys = new ArrayList();
            keys = this.gvDocumentUndo.SelectItems;
            keys.AddRange(this.gvDocumentUndoWithNoArchiveNum.SelectItems);
            keys.AddRange(this.gvDocumentDone.SelectItems);
            if (keys.Count == 0)
            {
                Alert("未选中任何数据！");
                return;
            }
            Session["dazl_selectedkeys_jj"] = keys;
            this.RegisterClientScriptBlock("alert", 
                string.Format("<script>window.open('AddHandoverDescView.aspx?from=dazl&archiveType={0}', '_blank', 'width=600,height=445,resizable=no');</script>" 
                ,(int)CurrentArchiveKind));
            //this.Response.Redirect(string.Format("PrintHandoverCatagory.aspx?from=dazl&archiveType={0}", (int)CurrentArchiveKind));
        }

        protected void bnPrintJuanCatagory_Click(object sender, EventArgs e)
        {
            ArrayList keys = new ArrayList();
            keys = this.gvDocumentUndo.SelectItems;
            keys.AddRange(this.gvDocumentUndoWithNoArchiveNum.SelectItems);
            keys.AddRange(this.gvDocumentDone.SelectItems);
            if (keys.Count == 0)
            {
                Alert("未选中任何数据！");
                return;
            }
            Session["dazl_jnml_selectedkeys"] = keys;
            this.Response.Redirect(string.Format("PrintJuanCatagoryView.aspx?from=dazl&archiveType={0}", (int)CurrentArchiveKind));
        }

        protected void bnPrintBoxCatagory_Click(object sender, EventArgs e)
        {
            ArrayList keys = new ArrayList();
            keys = this.gvDocumentUndo.SelectItems;
            keys.AddRange(this.gvDocumentUndoWithNoArchiveNum.SelectItems);
            keys.AddRange(this.gvDocumentDone.SelectItems);
            if (keys.Count == 0)
            {
                Alert("未选中任何数据！");
                return;
            }
            Session["dazl_hnml_selectedkeys"] = keys;
            this.Response.Redirect(string.Format("PrintBoxCatagoryView.aspx?from=dazl&archiveType={0}", (int)CurrentArchiveKind));
        }

        protected void btnPrintBeikaoTable_Click(object sender, EventArgs e)
        {
            ArrayList keys = new ArrayList();
            keys = this.gvDocumentUndo.SelectItems;
            keys.AddRange(this.gvDocumentDone.SelectItems);
            keys.AddRange(this.gvDocumentUndoWithNoArchiveNum.SelectItems);
            if (keys.Count == 0)
            {
                Alert("未选中任何数据！");
                return;
            }

            Session["dazl_bkb_selectedkeys"] = keys;
            Response.Redirect("../ArchiveFlowView/PrintBeikaoTableView.aspx?from=dazl&archiveType=" + (int)BaseArchiveType);

        }

        #region 生成档号

        private void DocumentArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;
            foreach (string key in keys)
            {
                IDocumentArchiveService DocumentArchiveService = UContainer.Resolve<IDocumentArchiveService>();
                ArchiveMangeModal.DOCUMENT_ARCHIVEDataTable dt = DocumentArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {
                    ArchiveMangeModal.DOCUMENT_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.DOCUMENT_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.DOCUMENT_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.DOCUMENT_ARCHIVEDataTable();
                    ArchiveMangeModal.DOCUMENT_ARCHIVERow newRow = dtArchive.NewDOCUMENT_ARCHIVERow();

                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = DocumentArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的文书类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }
                }
                ++archiveCodeNumber;
            }
        }

        private void AccountArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                IAccountArchiveService DocumentArchiveService = UContainer.Resolve<IAccountArchiveService>();
                ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVEDataTable dt = DocumentArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVEDataTable();
                    ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVERow newRow = dtArchive.NewACCOUNT_VOUCHER_ARCHIVERow();

                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = DocumentArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的会计类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }

                    PageFileService.SetPageFileArchiveNum(key, string.Format("{0}-{1}",newRow.ARCHIVENUM,i));
                }
                ++archiveCodeNumber;
            }
        }

        private void AudioArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                IAudioArchiveService AudioArchiveService = UContainer.Resolve<IAudioArchiveService>();
                ArchiveMangeModal.AUDIOVEDIO_ARCHIVEDataTable dt = AudioArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.AUDIOVEDIO_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.AUDIOVEDIO_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.AUDIOVEDIO_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.AUDIOVEDIO_ARCHIVEDataTable();
                    ArchiveMangeModal.AUDIOVEDIO_ARCHIVERow newRow = dtArchive.NewAUDIOVEDIO_ARCHIVERow();



                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = AudioArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的音像类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }
                }
                ++archiveCodeNumber;
            }
        }

        private void BuildProjectArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                IBuildProjectArchiveService buildProjectArchiveService = UContainer.Resolve<IBuildProjectArchiveService>();
                ArchiveMangeModal.BULIDPROJECT_ARCHIVEDataTable dt = buildProjectArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.BULIDPROJECT_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.BULIDPROJECT_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.BULIDPROJECT_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.BULIDPROJECT_ARCHIVEDataTable();
                    ArchiveMangeModal.BULIDPROJECT_ARCHIVERow newRow = dtArchive.NewBULIDPROJECT_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = buildProjectArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的基建类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }
                    PageFileService.SetPageFileArchiveNum(key, string.Format("{0}-{1}", newRow.ARCHIVENUM, i));
                }
                ++archiveCodeNumber;
            }
        }

        private void CDArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                ICDArchiveService cdArchiveService = UContainer.Resolve<ICDArchiveService>();
                ArchiveMangeModal.CD_ARCHIVEDataTable dt = cdArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.CD_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.CD_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.CD_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.CD_ARCHIVEDataTable();
                    ArchiveMangeModal.CD_ARCHIVERow newRow = dtArchive.NewCD_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = cdArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的光盘类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }
                }
                ++archiveCodeNumber;
            }
        }

        private void EquipArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                IEquipmentService EquipmentArchiveService = UContainer.Resolve<IEquipmentService>();
                ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable dt = EquipmentArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.EQUIPMENT_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.EQUIPMENT_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable();
                    ArchiveMangeModal.EQUIPMENT_ARCHIVERow newRow = dtArchive.NewEQUIPMENT_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = EquipmentArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的设备类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }

                    PageFileService.SetPageFileArchiveNum(key, string.Format("{0}-{1}", newRow.ARCHIVENUM, i));
                }
                ++archiveCodeNumber;
            }
        }

        private void OliSearchArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                IOilSearchArchiveService oilArchiveService = UContainer.Resolve<IOilSearchArchiveService>();
                ArchiveMangeModal.OLISEARCH_ARCHIVEDataTable dt = oilArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.OLISEARCH_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.OLISEARCH_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.OLISEARCH_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.OLISEARCH_ARCHIVEDataTable();
                    ArchiveMangeModal.OLISEARCH_ARCHIVERow newRow = dtArchive.NewOLISEARCH_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , newRow.WELLNUMBER, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = oilArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的油气勘探类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber, newRow.WELLNUMBER);

                        ++i;
                    }
                }
                ++archiveCodeNumber;
            }
        }

        private void RealKindArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                IRealKindArchiveService realArchiveService = UContainer.Resolve<IRealKindArchiveService>();
                ArchiveMangeModal.REALKIND_ARCHIVEDataTable dt = realArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.REALKIND_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.REALKIND_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.REALKIND_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.REALKIND_ARCHIVEDataTable();
                    ArchiveMangeModal.REALKIND_ARCHIVERow newRow = dtArchive.NewREALKIND_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = realArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的实物类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }
                }
                ++archiveCodeNumber;
            }
        }

        private void TechArchiveGenerate(ArrayList keys, int quanzonghaoSeriesNum, ref int i)
        {
            int archiveCodeNumber = quanzonghaoSeriesNum;

            foreach (string key in keys)
            {
                ITechArchiveService techArchiveService = UContainer.Resolve<ITechArchiveService>();
                ArchiveMangeModal.TECHNOLOGY_ARCHIVEDataTable dt = techArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.TECHNOLOGY_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.TECHNOLOGY_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (!string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.TECHNOLOGY_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.TECHNOLOGY_ARCHIVEDataTable();
                    ArchiveMangeModal.TECHNOLOGY_ARCHIVERow newRow = dtArchive.NewTECHNOLOGY_ARCHIVERow();

                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = ArchiveCodeGenerateHelper.Generate(
                        CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum
                        , null, ref archiveCodeNumber);

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = techArchiveService.SaveData(ds);

                    //若档号生成成功，则更新档案分类对应的档号流水
                    if (bReturn)
                    {
                        WriteUserLog(string.Format("用户{0}为ID为{1}的科研类型档案生成档号：{2}", CurrentUser.Real_Name, key, newRow.ARCHIVENUM), OracleLogType.ArchiveManage);
                        ArchiveCodeGenerateHelper.UpdateArchiveCodeNumber(
                            CurrentArchiveKind, this.CurrentUser.Org_FullFondsNum, archiveCodeNumber);

                        ++i;
                    }

                    PageFileService.SetPageFileArchiveNum(key, string.Format("{0}-{1}", newRow.ARCHIVENUM, i));
                }
                ++archiveCodeNumber;
            }
        }

        #endregion

        #region 删除档号

        protected void DocumentArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                IDocumentArchiveService DocumentArchiveService = UContainer.Resolve<IDocumentArchiveService>();
                ArchiveMangeModal.DOCUMENT_ARCHIVEDataTable dt = DocumentArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.DOCUMENT_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.DOCUMENT_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.DOCUMENT_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.DOCUMENT_ARCHIVEDataTable();
                    ArchiveMangeModal.DOCUMENT_ARCHIVERow newRow = dtArchive.NewDOCUMENT_ARCHIVERow();

                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = DocumentArchiveService.SaveData(ds);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的文书类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);
                    ++i;
                }
            }
        }

        private void AccountArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                IAccountArchiveService DocumentArchiveService = UContainer.Resolve<IAccountArchiveService>();
                ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVEDataTable dt = DocumentArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVEDataTable();
                    ArchiveMangeModal.ACCOUNT_VOUCHER_ARCHIVERow newRow = dtArchive.NewACCOUNT_VOUCHER_ARCHIVERow();

                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = DocumentArchiveService.SaveData(ds);
                    PageFileService.SetPageFileArchiveNum(key, string.Empty);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的会计类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);
                    ++i;
                }
            }
        }

        private void AudioArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                IAudioArchiveService AudioArchiveService = UContainer.Resolve<IAudioArchiveService>();
                ArchiveMangeModal.AUDIOVEDIO_ARCHIVEDataTable dt = AudioArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.AUDIOVEDIO_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.AUDIOVEDIO_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.AUDIOVEDIO_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.AUDIOVEDIO_ARCHIVEDataTable();
                    ArchiveMangeModal.AUDIOVEDIO_ARCHIVERow newRow = dtArchive.NewAUDIOVEDIO_ARCHIVERow();

                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = AudioArchiveService.SaveData(ds);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的声像类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);

                    ++i;
                }
            }
        }

        private void BuildProjectArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                IBuildProjectArchiveService buildProjectArchiveService = UContainer.Resolve<IBuildProjectArchiveService>();
                ArchiveMangeModal.BULIDPROJECT_ARCHIVEDataTable dt = buildProjectArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.BULIDPROJECT_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.BULIDPROJECT_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.BULIDPROJECT_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.BULIDPROJECT_ARCHIVEDataTable();
                    ArchiveMangeModal.BULIDPROJECT_ARCHIVERow newRow = dtArchive.NewBULIDPROJECT_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = buildProjectArchiveService.SaveData(ds);
                    PageFileService.SetPageFileArchiveNum(key, string.Empty);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的基建类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);
                    ++i;

                }
            }
        }

        private void CDArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                ICDArchiveService cdArchiveService = UContainer.Resolve<ICDArchiveService>();
                ArchiveMangeModal.CD_ARCHIVEDataTable dt = cdArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {
                    ArchiveMangeModal.CD_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.CD_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.CD_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.CD_ARCHIVEDataTable();
                    ArchiveMangeModal.CD_ARCHIVERow newRow = dtArchive.NewCD_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = cdArchiveService.SaveData(ds);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的光盘类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);

                    ++i;

                }
            }
        }

        private void EquipArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                IEquipmentService EquipmentArchiveService = UContainer.Resolve<IEquipmentService>();
                ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable dt = EquipmentArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.EQUIPMENT_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.EQUIPMENT_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable();
                    ArchiveMangeModal.EQUIPMENT_ARCHIVERow newRow = dtArchive.NewEQUIPMENT_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = EquipmentArchiveService.SaveData(ds);
                    PageFileService.SetPageFileArchiveNum(key, string.Empty);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的设备类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);
                    ++i;

                }
            }
        }

        private void OliSearchArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                IOilSearchArchiveService oilArchiveService = UContainer.Resolve<IOilSearchArchiveService>();
                ArchiveMangeModal.OLISEARCH_ARCHIVEDataTable dt = oilArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {
                    ArchiveMangeModal.OLISEARCH_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.OLISEARCH_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.OLISEARCH_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.OLISEARCH_ARCHIVEDataTable();
                    ArchiveMangeModal.OLISEARCH_ARCHIVERow newRow = dtArchive.NewOLISEARCH_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = oilArchiveService.SaveData(ds);

                    WriteUserLog(string.Format("用户{0}删除ID为{1}的油气勘探类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);
                    ++i;

                }
            }
        }

        private void RealKindArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                IRealKindArchiveService realArchiveService = UContainer.Resolve<IRealKindArchiveService>();
                ArchiveMangeModal.REALKIND_ARCHIVEDataTable dt = realArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.REALKIND_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.REALKIND_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.REALKIND_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.REALKIND_ARCHIVEDataTable();
                    ArchiveMangeModal.REALKIND_ARCHIVERow newRow = dtArchive.NewREALKIND_ARCHIVERow();


                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = realArchiveService.SaveData(ds);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的实物类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);

                    ++i;

                }
            }
        }

        private void TechArchiveCodeDelete(ArrayList keys, ref int i)
        {
            foreach (string key in keys)
            {
                ITechArchiveService techArchiveService = UContainer.Resolve<ITechArchiveService>();
                ArchiveMangeModal.TECHNOLOGY_ARCHIVEDataTable dt = techArchiveService.GetAllDocumenArchivetDataById(key);
                if (dt != null && dt.Rows.Count > 0)
                {

                    ArchiveMangeModal.TECHNOLOGY_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.TECHNOLOGY_ARCHIVERow;

                    //若已生成档号则直接跳过
                    if (string.IsNullOrEmpty(row.ARCHIVENUM))
                        continue;

                    DataSet ds = new DataSet();
                    ArchiveMangeModal.TECHNOLOGY_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.TECHNOLOGY_ARCHIVEDataTable();
                    ArchiveMangeModal.TECHNOLOGY_ARCHIVERow newRow = dtArchive.NewTECHNOLOGY_ARCHIVERow();

                    newRow.ItemArray = row.ItemArray;
                    //档号
                    newRow.ARCHIVENUM = string.Empty;

                    dtArchive.NewRow();
                    dtArchive.Rows.Add(newRow);
                    dtArchive.AcceptChanges();
                    newRow.SetModified();
                    ds.Tables.Add(dtArchive);
                    bool bReturn = techArchiveService.SaveData(ds);
                    PageFileService.SetPageFileArchiveNum(key, string.Empty);
                    WriteUserLog(string.Format("用户{0}删除ID为{1}的科研类型档案档号", CurrentUser.Real_Name, key), OracleLogType.ArchiveManage);
                    ++i;

                }
            }
        }

        #endregion
    }
}
